package etr.bk.gui.lpan;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import etr.bk.gui.PictureFromfFile;

public class PictPan extends JPanel
{
	private JPanel panel;
	private BufferedImage img;
	private JLabel label;
	
	private String textForLabel;
	
	private int id;
	
	
	public PictPan(int iden, String strLabel, BufferedImage image) 
	{
		this.img = image;
		
		this.textForLabel = strLabel;
		
		this.label = new JLabel(strLabel);
		this.id = iden;
		
		this.setLayout(new FlowLayout(FlowLayout.LEFT));
		
		this.panel = new JPanel(){
			public void paintComponent(Graphics g)
			{
				//g.drawImage(img, 0, 0,img.getHeight()-20,img.getWidth()-20, null);//+ scaling
				
				if (img != null) g.drawImage(img, 0, 0,60,60, null);//+ scaling
				else g.clearRect(0, 0, this.getWidth(),this.getHeight());
			}
		};
		
		this.panel.setPreferredSize(new Dimension(60, 60));
		
		
		this.add(panel);
		this.add(label);
		
		/*
		PictureFromfFile p = new PictureFromfFile(new File("D:/strawberry.jpg"));
		this.img = p.getImageFromFile();*/
		
		this.setBorder(BorderFactory.createEtchedBorder());
		
		this.setOpaque(true);
	}
	
	public void setSelect(boolean sel, JList<?> list)
	{
		if (sel) {
            this.setBackground(list.getSelectionBackground());
            this.setForeground(list.getSelectionForeground());
        } else {
            this.setBackground(list.getBackground());
            this.setForeground(list.getForeground());
        }
	}
	
	public void setText(String str)
	{
		this.label.setText(str);
	}
	
	public void setFoto(BufferedImage image){
		this.img = image;
	}
	
	public String getText()
	{
		return this.textForLabel;
	}

	public int getId()
	{
		return id;
	}
		
}
